import globals from 'globals'
import eslintJs from '@eslint/js'
import eslintPluginVue from 'eslint-plugin-vue'
import eslintTs from 'typescript-eslint'
import parserVue from 'vue-eslint-parser'
import pluginPrettierRecommendedConfigs from 'eslint-plugin-prettier/recommended'
import { readFile } from 'node:fs/promises'

const vueAutoImportFile = new URL('./types/.eslintrc-auto-imports.json', import.meta.url)
const vueAutoImportGlobals = JSON.parse(await readFile(vueAutoImportFile, 'utf-8'))

const eslintConfig = [
	// eslint 默认推荐规则
	eslintJs.configs.recommended,
	// ts 默认推荐规则
	...eslintTs.configs.recommended,
	// vue3 基础推荐规则
	...eslintPluginVue.configs['flat/recommended'],
	// prettier 默认推荐规则
	pluginPrettierRecommendedConfigs,
	{
		ignores: ['src-tauri/**/*', 'node_modules/*', 'dist/*'],
		languageOptions: {
			globals: {
				...globals.browser,
				...globals.es2020,
				...globals.node,
				...vueAutoImportGlobals.globals,
				__APP_ENV__: true,
			},
			ecmaVersion: 2020,
			parser: parserVue,
			parserOptions: {
				parser: eslintTs.parser,
				ecmaFeatures: {
					jsx: true,
				},
			},
		},
		rules: {
			'no-console': [0],
			'@typescript-eslint/no-unused-vars': 1,
			'@typescript-eslint/no-explicit-any': 0,
			'vue/multi-word-component-names': 0,
		},
	},
]

export default eslintConfig
